package com.example.component.c_broadcast.custom

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.component.databinding.ActivityCABinding

class CAActivity : AppCompatActivity() {
    private lateinit var binding: ActivityCABinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = ActivityCABinding.inflate(layoutInflater)
        val view = binding.root
        setContentView(view)
        ViewCompat.setOnApplyWindowInsetsListener(view) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        binding.button.setOnClickListener {
            /**
             * 发送广播
             */
            val intent = Intent("com.example.broadcasttest.MY_BROADCAST")
            intent.setPackage(packageName)
//            标准广播
//            sendBroadcast(intent)
//            有序广播
            sendOrderedBroadcast(intent, null)
        }
    }

    companion object {
        fun actionStart(context: Context) {
            val intent = Intent(context, CAActivity::class.java)
            context.startActivity(intent)
        }
    }

}